package com.yanyeori.webtest.service.impl.redistest;

import com.yanyeori.framework.core.interfaces.PublishEventUtil;
import com.yanyeori.framework.core.util.JacksonUtil;
import com.yanyeori.webtest.constant.TestEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * @author chenkuan
 * @version v1.0
 * @desc
 * @date 20/08/20 020 15:04
 */
@Slf4j
@Service
public class PublishTest {

    @Autowired
    private PublishEventUtil publishEventUtil;

    public void publishEvent(boolean isRemote) {
        TestEvent event = new TestEvent();
        event.setName("CHNE");
        event.setRemote(isRemote);
        publishEventUtil.publishEvent(event, isRemote);
    }

    @EventListener
    @Async
    public void listenerEvent(TestEvent event) {
        log.info("收到通知事件:{}", JacksonUtil.toJson(event));
    }
}
